package com.lancoo.cvas.pojo.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.lancoo.cvas.entity.Major;
import com.lancoo.cvas.entity.PlanTeaching;
import com.lancoo.cvas.entity.PlanTeachingStudent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Scheme
 * @Description 新教务系统教学计划
 * @Author quin
 * @Date 2023/3/1 17:15
 */
@NoArgsConstructor
@Data
@AllArgsConstructor
public class Scheme {
    @JsonProperty("SchemeID")
    private String schemeID;
    @JsonProperty("SchemeType")
    private Integer schemeType;

    @JsonProperty("MajorID")
    private String majorID;
    @JsonProperty("MajorName")
    private String majorName;

    @JsonProperty("GradeID")
    private String gradeID;
    @JsonProperty("GradeName")
    private String gradeName;

    @JsonProperty("Version")
    private String version;
    @JsonProperty("ExtraCredit")
    private Integer extraCredit;
    @JsonProperty("CourseList")
    private List<CourseListDTO> courseList;
    @JsonProperty("StudentList")
    private List<StudentListDTO> studentList;

    @NoArgsConstructor
    @Data
    public static class CourseListDTO {
        @JsonProperty("PlanID")
        private String planID;
        @JsonProperty("PlanType")
        private String planType;
        @JsonProperty("SubjectID")
        private String subjectID;
        @JsonProperty("SubjectName")
        private String subjectName;
        @JsonProperty("PlanKindID")
        private String planKindID;
        @JsonProperty("PlanKindName")
        private String planKindName;
        @JsonProperty("CourseProp")
        private Integer courseProp;
        @JsonProperty("CourseCode")
        private String courseCode;
        @JsonProperty("CourseName")
        private String courseName;
        @JsonProperty("TotalHour")
        private Integer totalHour;
        @JsonProperty("Credit")
        private Double credit;
        @JsonProperty("Terms")
        private String terms;

        @JsonProperty("EnglishName")
        private String englishName;
        @JsonProperty("Introduction")
        private String introduction;
        @JsonProperty("MajorProp")
        private Integer majorProp;
        @JsonProperty("LectureHours")
        private Integer lectureHours;
        @JsonProperty("ExperimentHours")
        private Integer experimentHours;
        @JsonProperty("OperationHours")
        private Integer operationHours;
        @JsonProperty("OtherHours")
        private Integer otherHours;
    }

    @NoArgsConstructor
    @Data
    public static class StudentListDTO {
        @JsonProperty("UserID")
        private String userID;
    }

    public PlanTeaching toPlanTeaching(Integer taskId) {
        return new PlanTeaching()
                .setBaseTeachingPlanId(getSchemeID())
                .setTaskId(taskId)
                .setGradeId(getGradeID())
                .setGradeName(getGradeName())
                .setBaseMajorId(getMajorID())
                .setMajorName(getMajorName())
                .setMajorVersionName(getVersion())
                .setStudentCount(getStudentList().size())
                .setIsEnable(0);
    }

    public Major toMajor(Integer taskId) {
        return new Major()
                .setTaskId(taskId)
                .setBaseMajorId(getMajorID())
                .setMajorName(getMajorName());
    }

    public List<PlanTeachingStudent> toPlanTeachingStudent(Integer taskId) {
        List<PlanTeachingStudent> planTeachingStudents = new ArrayList<>();
        for (StudentListDTO studentListDTO : getStudentList()) {
            planTeachingStudents.add(new PlanTeachingStudent()
                    .setTaskId(taskId)
                    .setBaseTeachingPlanId(getSchemeID())
                    .setBaseStudentId(studentListDTO.getUserID())
            );
        }
        return planTeachingStudents;
    }
}
